<?php

class QSettings
{
    private $sectionName;
    private $QXC;
    
    function __construct($qxc)
    {
        $this->QXC = $qxc;
        $this->Load('system');
    }

    /**
     * @return mixed
     */
    public function Get($name, $default = false)
    {
        return $this->{$name} ? $this->{$name} : $default;
    }

    /**
     * @return bool
     */
    public function Set($name, $value)
    {
        $this->{$name} = $value;

        return true;
    }

    public function Load($section)
    {
        $this->sectionName = $section;

        $arr = $this->QXC->Db->Query("SELECT * FROM qxc_options WHERE Section='{$this->sectionName}'");

        $this->ToObject($arr);

        return $this;
    }

    public function Save($arr, $module)
    {
        foreach ((array)$arr as $key=>$val)
        {
            $arr = $this->QXC->Db->Query("UPDATE qxc_options SET OptionValue='{$val}'
                WHERE OptionName='{$key}' AND Section='{$module}'");
        }
    }

    private function ToObject($arr)
    {
        foreach ($arr as $val)
        {
            $this->{$val['OptionName']} = $val['OptionValue'];            
        }
    }
}